package com.mes.biz.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.domain.BaseEntity;
import com.mes.common.core.service.BaseServiceImpl;
import com.mes.framework.cache.DeptUtils;
import com.mes.common.core.domain.entity.SysDept;
import com.mes.common.utils.StringUtils;
import com.mes.biz.mapper.BizProductionProcessMapper;
import com.mes.biz.domain.BizProductionProcess;
import com.mes.biz.service.BizProductionProcessService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * 生产工序Service业务层处理
 * @author hwg
 * @email hwg
 * @date 2023-03-30
 */
@Service
@Transactional(readOnly = true)
public class BizProductionProcessServiceImpl extends BaseServiceImpl<BizProductionProcessMapper, BizProductionProcess> implements BizProductionProcessService {

    private static final Logger log = LoggerFactory.getLogger(BizProductionProcessServiceImpl.class);

    /**
     * 获取单条数据
     * @param bizProductionProcess 生产工序
     * @return 生产工序
     */
    @Override
    public BizProductionProcess get(BizProductionProcess bizProductionProcess) {
        BizProductionProcess dto = super.get(bizProductionProcess);
        if (StringUtils.isNotEmpty(dto.getDeptId())){
			SysDept sysDept = DeptUtils.getSysDept(dto.getDeptId());
			if (null != sysDept){
				dto.setDeptIdName(sysDept.getDeptName());
			}
        }
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 生产工序id
     * @return 生产工序
     */
    @Override
    public BizProductionProcess get(String id) {
        BizProductionProcess dto = super.get(id);
		if (StringUtils.isNotEmpty(dto.getDeptId())){
			SysDept sysDept = DeptUtils.getSysDept(dto.getDeptId());
			if (null != sysDept){
				dto.setDeptIdName(sysDept.getDeptName());
			}
        }
        return dto;
    }

    /**
     * 查询生产工序列表
     * @param bizProductionProcess 生产工序
     * @return 生产工序
     */
    @Override
    public List<BizProductionProcess> findList(BizProductionProcess bizProductionProcess) {
		List<BizProductionProcess> bizProductionProcessList = super.findList(bizProductionProcess);
		if (!CollectionUtils.isEmpty(bizProductionProcessList)) {
			bizProductionProcessList.stream().forEach(dto -> {
				if (StringUtils.isNotEmpty(dto.getDeptId())){
					SysDept sysDept = DeptUtils.getSysDept(dto.getDeptId());
					if (null != sysDept){
						dto.setDeptIdName(sysDept.getDeptName());
					}
				}
			});
		}
        return bizProductionProcessList;
    }

    /**
     * 分页查询生产工序列表
     * @param bizProductionProcess 生产工序
     * @return 生产工序
     */
    @Override
    public PageInfo<BizProductionProcess> findPage(BizProductionProcess bizProductionProcess) {
		PageInfo<BizProductionProcess> page = super.findPage(bizProductionProcess);
		if (!CollectionUtils.isEmpty(page.getList())) {
            page.getList().stream().forEach(dto -> {
				if (StringUtils.isNotEmpty(dto.getDeptId())){
					SysDept sysDept = DeptUtils.getSysDept(dto.getDeptId());
					if (null != sysDept){
						dto.setDeptIdName(sysDept.getDeptName());
					}
				}
            });
        }
        return page;
    }

    /**
     * 保存生产工序
     * @param bizProductionProcess
     * @return 结果
     */
    @Override
    public boolean save(BizProductionProcess bizProductionProcess) {
        return super.save(bizProductionProcess);
    }

    /**
     * 删除生产工序信息
     * @param bizProductionProcess
     * @return 结果
     */
    @Override
    public boolean remove(BizProductionProcess bizProductionProcess) {
        return super.remove(bizProductionProcess);
    }

    /**
     * 批量删除生产工序
     * @param ids 需要删除的生产工序ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteBizProductionProcessByIds(String[] ids) {
        return mapper.deleteBizProductionProcessByIds(ids, BaseEntity.DEL_FLAG_DELETE);
    }

}
